/**通过mutation间接更新state的多个方法的对象 */
import {
  RECEIVE_ADDRESS,
  RECEIVE_CATEGORYS,
  RECEIVE_SHOPS
} from "./mutation-types"
import {
  reqAddress,
  reqFoodCategorys,
  reqShops
} from '../api'
export default {
  // 异步获取地址
  async getAddress({commit,state}){
    // 发送异步请求
    const {latitude,longitude, }=state
    const geohash=`${latitude},${longitude}`
    let result=await reqAddress(geohash)
    // 提交mutation
    if(result['code']===0){
      const address=result.data
      // 提交mutation
      commit(RECEIVE_ADDRESS,{address})
    }
  },
  // 异步获取地址
  async getCategorys({commit}){
    // 发送异步请求
    let result=await reqFoodCategorys()
    // 提交mutation
    if(result['code']===0){
      const categorys=result.data
      // 提交mutation
      commit(RECEIVE_CATEGORYS,{categorys})
    }
  },
  // 异步获取地址
  async getShops({commit}){
    // 发送异步请求
    let result=await reqShops()
    // 提交mutation
    if(result['code']===0){
      const shops=result.data
      // 提交mutation
      commit(RECEIVE_SHOPS,{shops})
    }
  }
}
